package com.gongjian.web.dcontroller;

import com.gongjian.database.entity.Activity;
import com.gongjian.database.entity.User;
import com.gongjian.database.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author donting
 * @Description
 * @create 2019-03-31 17:10
 */
@RestController
public class DactivityContoller {

    @Autowired
    ActivityService activityService;

    @RequestMapping("/activity/activityName")
    public String addActivity(String activityName, int daojishi,String activityAddress, HttpSession session){
        long now=  System.currentTimeMillis()/1000;
        long mm=daojishi*60;//秒
        System.out.println(now+mm);
        System.out.println(activityName+daojishi);
        //签到结束时间
        Date date = new Date((now+mm)*1000);
        Activity activity=new Activity();
        activity.setActivityName(activityName);
        Date date1=new Date();
        Timestamp timestamp = new Timestamp(date1.getTime());
        activity.setActivityCreateTime(timestamp);
        Timestamp ret = new Timestamp(date.getTime());
        activity.setActivityRegisterTime(ret);
        activity.setActivityAddress(activityAddress);
        User user=(User)session.getAttribute("user");
        activity.setUserId(user.getUserId());
        return activityService.addActivity(activity);
    }
    @RequestMapping("/activity/findAllactivity")
    public String findAllactivity(int Page,int PageSize,HttpSession httpSession){
        User user=(User)httpSession.getAttribute("user");
        return activityService.findAllactivity(Page,PageSize,user.getUserId());
    }
}
